﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using TableTopWidgets;

namespace TabletopWidgetTestApp
{
    /// <summary>
    /// Interaction logic for DemoMenu.xaml
    /// </summary>
    public partial class DemoMenu : Grid
    {

        private int _buttonCount = 4;
        private bool _isThirdRowEnabled = true;

        public DemoMenu()
        {
            InitializeComponent();
        }

        void Close(object sender, RoutedEventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void removeFromRow(object sender, RoutedEventArgs e)
        {
            if (_buttonCount == 4)
            {
                //Enable the add button
                Add_Button.Style = (Style)FindResource("AddDefault");
            }
            if (_buttonCount > 0)
                RemoveButton();
            if (_buttonCount == 0)
            {
                //Disable this button
                Remove_Button.Style = (Style)FindResource("Disabled");
            }
        }
        private void addToRow(object sender, RoutedEventArgs e)
        {
            if (_buttonCount == 0)
            {
                //Enable the remove button
                Remove_Button.Style = (Style)FindResource("RemoveDefault");
            }
            if (_buttonCount < 4)
                AddButton();
            if (_buttonCount == 4)
            {
                //Disable this button
                Add_Button.Style = (Style)FindResource("Disabled");
            }
        }
        private void toggleThirdRow(object sender, RoutedEventArgs e)
        {
            _isThirdRowEnabled = !_isThirdRowEnabled;
            if (_isThirdRowEnabled)
            {
                //Enable Row
                //Enable relevent Add/Remove buttons
                if (_buttonCount > 0)
                    Remove_Button.Style = (Style)FindResource("RemoveDefault");
                if (_buttonCount < 4)
                    Add_Button.Style = (Style)FindResource("AddDefault");
                //Set all buttons to visible
                if (_buttonCount > 0)
                    Button3A.Style = (Style)FindResource("Visible");
                if (_buttonCount > 1)
                    Button3B.Style = (Style)FindResource("Visible");
                if (_buttonCount > 2)
                    Button3C.Style = (Style)FindResource("Visible");
                if (_buttonCount > 3)
                    Button3D.Style = (Style)FindResource("Visible");
            }
            else
            {
                //Disable Row
                //Disable Add/Remove buttons
                Remove_Button.Style = (Style)FindResource("Disabled");
                Add_Button.Style = (Style)FindResource("Disabled");
                //Set all buttons to invisible
                Button3A.Style = (Style)FindResource("Invisible");
                Button3B.Style = (Style)FindResource("Invisible");
                Button3C.Style = (Style)FindResource("Invisible");
                Button3D.Style = (Style)FindResource("Invisible");
            }
        }

        private void AddButton()
        {
            _buttonCount++;
            if (_buttonCount == 1)
            {
                Button3A.Style = (Style)FindResource("Visible");
            }
            if (_buttonCount == 2)
            {
                Button3B.Style = (Style)FindResource("Visible");
            }
            if (_buttonCount == 3)
            {
                Button3C.Style = (Style)FindResource("Visible");
            }
            if (_buttonCount == 4)
            {
                Button3D.Style = (Style)FindResource("Visible");
            }
        }
        private void RemoveButton()
        {
            _buttonCount--;
            if (_buttonCount == 0)
            {
                Button3A.Style = (Style)FindResource("Invisible");
            }
            if (_buttonCount == 1)
            {
                Button3B.Style = (Style)FindResource("Invisible");
            }
            if (_buttonCount == 2)
            {
                Button3C.Style = (Style)FindResource("Invisible");
            }
            if (_buttonCount == 3)
            {
                Button3D.Style = (Style)FindResource("Invisible");
            }
        }

        private void Highlight(object sender, MouseEventArgs e)
        {
            RadialButton button = (RadialButton)sender;
            button.Foreground = Brushes.Blue;
        }

        private void Dehighlight(object sender, MouseEventArgs e)
        {
            RadialButton button = (RadialButton)sender;
            button.Foreground = Brushes.Black;
        }

        public void ChangePosition(double x, double y)
        {
            Canvas.SetTop(this, y - 30);
            Canvas.SetLeft(this, x - 20);
        }

        public void RevealImage1(object sender, RoutedEventArgs e)
        {
            Canvas c = (Canvas)Parent;
            RNTWindow win = (RNTWindow) c.Parent;
            win.RevealImage("Hydrangeas.jpg");
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
        public void RevealImage2(object sender, RoutedEventArgs e)
        {
            Canvas c = (Canvas)Parent;
            RNTWindow win = (RNTWindow)c.Parent;
            win.RevealImage("Jellyfish.jpg");
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
        public void RevealImage3(object sender, RoutedEventArgs e)
        {
            Canvas c = (Canvas)Parent;
            RNTWindow win = (RNTWindow)c.Parent;
            win.RevealImage("Koala.jpg");
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
        public void RevealImage4(object sender, RoutedEventArgs e)
        {
            Canvas c = (Canvas)Parent;
            RNTWindow win = (RNTWindow)c.Parent;
            win.RevealImage("Lighthouse.jpg");
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
